package com.example.studyproject.loginInterceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @program: SalaryProject
 * @description: 登录
 * @author: kangwei
 * @create: 2023-03-10 09:34
 **/
@RestController
@RequestMapping("user")
public class LoginController {
    @PostMapping("/login")
    public boolean login(HttpServletRequest request, String userName, String userPwd) {
        // 非空校验
        if (StringUtils.hasLength(userName) && StringUtils.hasLength(userPwd)) {
            // 从请求中获取session
            HttpSession session = request.getSession();
            session.setAttribute("userinfo", "admin");
            return true;
        }
        return false;
    }

    @PostMapping("/register")
    public boolean register() {
        System.out.println("用户注册");
        return false;
    }

    @GetMapping
    public String getUserById(){
        int i =1/0;
        return "user";
    }
}
